<template>
  <section>
  <el-form label-width="80px">
    <el-form-item label="标题">
      <el-input size="mini" v-model="activity.title" style="width: 200px"></el-input>
    </el-form-item>
    <el-form-item label="起止时间">
      <el-row>
        <el-col :span="11">
          <el-date-picker size="mini" v-model="activity.start" type="datetime"
                          placeholder="选择日期时间" default-time="12:00:00"
                          format="yyyy-MM-dd HH:mm:ss" value-format="timestamp">
          </el-date-picker>
        </el-col>
        <el-col :span="2">~</el-col>
        <el-col :span="10">
          <el-date-picker size="mini" v-model="activity.end" type="datetime"
                          placeholder="选择日期时间" default-time="12:00:00" value-format="timestamp"
                          format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-col>
      </el-row>
    </el-form-item>
    <el-form-item label="是否重复">
      <el-switch v-model="activity.repeatable"/>
    </el-form-item>
    <el-form-item>
      <el-button size="mini" type="success" @click="saveActBtn(activity)">保存</el-button>
    </el-form-item>
  </el-form>
  </section>
</template>

<script>
  import dateFormater from '@/common/date-formater'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import errHandler from '@/assets/errHandler'
  export default {
    name: "activityEdit",
    props: ['activity'],
    data(){
      return{
      }
    },
    computed:{
      ...mapGetters(['department']),
    },
    created(){

    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      saveActBtn(form){
        form.start = dateFormater.formatDatetime(form.start)
        form.end = dateFormater.formatDatetime(form.end)
        if(form.id){
          this.updateActivity(form)
        }else {
          this.createActivity(form)
        }
      },
      createActivity(data){
        this.fetch({name:"createActivity",data})
          .then(res=>{
            console.log(res)
            this.$message({type:'success',message:'创建成功！'})
            this.$emit('cancel',res)
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      updateActivity(data){
        this.fetch({name:"updateActivity",data})
          .then(res=>{
            this.$message({type:'success',message:'更新成功！'})
            this.$emit('cancel',res)
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      }
    }
  }
</script>

<style scoped>

</style>
